package com.study;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.study.util.FileUtil;

import java.util.ArrayList;
import java.util.List;

public class Test2 {

    public static void main(String[] args) {
//       int s = new BigDecimal(5).divide(new BigDecimal(0.6),1, RoundingMode.DOWN)
//                .multiply(new BigDecimal(10)).subtract(new BigDecimal(8*10)).intValue();
//       if(s < 0) {
//           System.out.println("不需要创建拼团");
//       }else {
//           if(s == 0) {
//               s = 1;
//           }
//           int n = s / 10 + (s % 10 > 0?1:0);
//           System.out.println("需要创建拼团:"+n);
//       }
//        TimeZone timeZone = TimeZone.getDefault();
//        System.out.println(timeZone.getID());
//        System.out.println(timeZone.getDisplayName());

//        Calendar cal = Calendar.getInstance();
//        int offset = cal.get(Calendar.ZONE_OFFSET);
//        cal.add(Calendar.MILLISECOND, -offset);
//        Long timeStampUTC = cal.getTimeInMillis();
//        Long timeStamp = System.currentTimeMillis();
//        Long timeZone = (timeStamp - timeStampUTC) / (1000 * 3600); System.out.println(timeZone.intValue());
//        String.valueOf(timeZone);

//        int n = 10000;
//        for (int i = 1; i <= 100; i++) {
//            int temp = n+i;
//            String sql = "INSERT INTO `acticity_robot`( `robot_id`, `robot_name`) VALUES ("+temp+", 'robot_name_"+temp+"');";
//            System.out.println(sql);
//        }

        System.out.println(System.getenv("ROCKETMQ_HOME"));
        System.out.println(System.getProperty("ROCKETMQ_HOME"));

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 105; i++) {
            list.add(i);
        }

        for (int i = 1; i <= 12; i++) {
            int fromIndex = (i - 1) * 10;
            if (fromIndex > list.size()) {
                break;
            }

            int toIndex = i * 10;
            if (toIndex > list.size()) {
                toIndex = list.size();
            }
            List<Integer> subList = list.subList(fromIndex, toIndex);
            System.out.println(JSONObject.toJSON(subList));
        }

        List<String> strings = FileUtil.readTxtFileIntoStringArrList(
                "/Users/wanghuilong/IdeaProjects/lazy/src/main/resources/file/1.txt", null);

        String sql1 = "update external_b2b_drug set sort = where `code` = ";

        String sql2 = "update external_b2b_drug set purchase_num = ,sort = where `code` = ";
        List<String> listResult = new ArrayList<>();
        JSONArray codes = new JSONArray();
        for (int i = 0; i < strings.size(); i++) {
            String s = strings.get(i);
            String[] split = s.trim().split("\t");
            if (split.length == 3) {
                String str = "update external_b2b_drug set sort =" + split[0] + " where `code` = '" + split[2] + "';";
                listResult.add(str);
            } else if (split.length == 4) {
                String str = "update external_b2b_drug set purchase_num = " + split[3] + ",sort =" + split[0] + " where `code` = '" + split[2] + "';";
                listResult.add(str);
            } else {
                System.out.println(s);
            }
            codes.add(split[2]);
        }
        FileUtil.writeToFileByLine(listResult, "/Users/wanghuilong/IdeaProjects/lazy/src/main/resources/file/2.txt");
        System.out.println(codes.toJSONString());

        list = new ArrayList<>();
        for (int i = 0; i < 105; i++) {
            list.add(i);
        }

        int pageSize = 10;

        int page = list.size() / pageSize + (list.size() % pageSize > 0 ? 1 : 0);

        for (int i = 1; i <= page; i++) {
            int fromIndex = (i - 1) * pageSize;
            if (fromIndex > list.size()) {
                break;
            }

            int toIndex = i * pageSize;
            if (toIndex > list.size()) {
                toIndex = list.size();
            }
            List<Integer> subList = list.subList(fromIndex, toIndex);
            System.out.println(JSONObject.toJSON(subList));
        }

    }

}

